<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑优惠券</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/temp/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/temp/css/frame.css">

    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>           
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>编辑优惠券</legend>
</fieldset>

<form class="layui-form layui-form-pane" action="" lay-filter="example" style="padding: 20px">
    <input type="hidden" name="id" value="{$info.id}" lay-verify="id">

    <div class="layui-form-item">
        <label class="layui-form-label">所属店铺</label>
        <div class="layui-input-inline" style="width: 40%">
            <select name="admin_id">
                <option value="{$info->getData('admin_id')}">{$info.admin_id.nickname}</option>
                {foreach $shop_list as $k => $v}
                <option value="{$v.id}">{$v.nickname}</option>
                {/foreach}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="text" name="name" value="{$info.name}" lay-verify="name" autocomplete="off" placeholder="请输入优惠券名称" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span style="color: red">*</span> 长度1-30个字符
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">优惠金额</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="number" name="price" value="{$info.price}" lay-verify="price" autocomplete="off" placeholder="请输入优惠金额" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">开始时间</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="text" name="start_time" value="{$info.start_time}" id="start" lay-verify="start_time" placeholder="请选择开始时间" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">结束时间</label>
        <div class="layui-input-inline" style="width: 40%">
            <input type="text" name="end_time" value="{$info.end_time}" id="end" lay-verify="end_time" placeholder="请选择结束时间" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" pane="" style="width: 47.5%">
        <label class="layui-form-label">适用范围</label>
        <div class="layui-input-block">
            {foreach $info['scope_all'] as $k => $v}
                {if (in_array($k, $info['scope_arr']) != false)}
                    <input type="checkbox" name="scope" value="{$k}" title="{$v}" checked>
                {else /}
                    <input type="checkbox" name="scope" value="{$k}" title="{$v}">
                {/if}
            {/foreach}
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
            <a href="javascript:history.back(-1)" class="layui-btn layui-btn-primary">返回</a>
        </div>
    </div>
</form>
          
<script src="/static/temp/layui/layui.js" charset="utf-8"></script>

<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,layedit = layui.layedit;

        // 日期
        laydate.render({
            elem: '#start'
        });

        laydate.render({
            elem: '#end'
        });

        // 监听提交
        form.on('submit(submit)', function(data){
            let scope = ''
            $("input[name='scope']:checked").each(function(){
                scope += $(this).val() + ','
            })

            data.field.scope = scope

            // 加载中样式... 
            let loading = layer.msg('正在修改，请稍后...', {icon: 16, shade: 0.3, time:0});

            $.post('{:url("Coupon/setCouponEdit")}', data.field, function(res){
                if(res.code == 0){
                    layer.msg(res.msg, {icon: 1,time: 1500}, function(){
                        window.location.href = "{:url('Coupon/coupon_list')}";
                    });
                }else{
                    layer.msg(res.msg, {icon: 2});
                }
            })

            return false;
        });
    });
</script>
</body>
</html>